<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022-01-24
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
    <link rel="stylesheet" href="js/layui/css/layui.css">
    <link rel="stylesheet" href="css/login.css">

    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/layui/layui.js"></script>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="button" class="layui-btn" lay-submit lay-filter="login" value="登录" />
            <input type="button" class="layui-btn" id="toCreateUser"   value="注册" />

        </div>
    </div>
</form>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use( function() {
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        $("#toCreateUser").on("click",function (){
           location.href="createUser.jsp"
        });
        // 监听注册表单的提交事件
        form.on("submit(login)", function (res) {
            console.log(res);


            console.log(res.field);
            $.post({
                url: "user/isExit.do",
                data: {"name": res.field.name, "password": res.field.password},
                success: function (c) {
                    if (c.data==0){
                        layer.msg("用户名不存在");
                    }
                    else if (c.data == 3) {
                        layer.msg("密码错误");
                    }
                   else if (c.data == 1) {
                        layer.msg("登录成功");
                        location.href="user/toCreateUser.do?page=index";
                    } else {
                        console.log("处理异常" + c.msg);
                    }
                }
            });

        });
    });
</script>
</body>
</html>
